package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.common.query.DestinationQueryObject;
import cn.wolfcode.luowowo.common.query.QueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("destination")
public class DestinationController {

    @Reference
    private IDestinationService destinationService;

    @RequestMapping("list")
    public Object list(@ModelAttribute("qo") DestinationQueryObject qo, Model model){
        //不是顶级的时候,查询父级目的地
        if(qo.getParentId() > 0){
            List<Destination> toasts = destinationService.getToasts(qo.getParentId());
            model.addAttribute("toasts",toasts);
        }
        PageInfo pageInfo = destinationService.selectForList(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "destination/list";
    }

    @RequestMapping("changeHotState")
    @ResponseBody
    public Object changeHotState(Long id,Integer hot){
        return  destinationService.chageHotState(id,hot);
    }

    @RequestMapping("setInfo")
    @ResponseBody
    public Object setInfo(Long id,String info){
        return destinationService.updateInfo(id,info);
    }

}
